package com.zx._09_架构.重构;

/**
 * @program: knowledge
 * @description:
 * @author: xue.zhang
 * @create: 2021-11-17 10:17
 */
public class 嵌套条件分支的优化 {

    /**
     * case 1
     **/
    class BadExample1 {

        public void someMethod(Object A, Object B) {
            if (A != null) {
                if (B != null) {
                    //code[1]
                } else {
                    //code[3]
                }
            } else {
                //code[2]
            }
        }
    }

    /* ---------------------分割线---------------------- */
    class GoodExample1 {

        public void someMethod(Object A, Object B) {
            if (A == null) {
                //code[2]
                return;
            }
            if (B == null) {
                //code[3]
                return;
            }
            //code[1]
        }
    }


    /**
     * case 2
     **/
    class BadExample2 {

        public void someMethod(Object A, Object B) {
            if (A != null) {
                if (B != null) {
                    //code
                }
            }
        }
    }

    /* ---------------------分割线---------------------- */
    class GoodExample2 {

        public void someMethod(Object A, Object B) {
            if (A != null && B != null) {
                //code
            }
        }
    }


}
